package com.ruoyi.mes.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.exception.GlobalException;
import com.ruoyi.mes.domain.ProInfo;
import com.ruoyi.mes.vo.device.AvgUDPVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mes.domain.PickInfo;
import com.ruoyi.mes.service.IPickInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 领料信息Controller
 *
 * @author LongAndHao
 * @date 2023-04-04
 */
@Api(tags = "领料信息")
@RestController
@RequestMapping("/mes/pick")
public class PickInfoController extends BaseController {
    @Autowired
    private IPickInfoService pickInfoService;

    /**
     * 查询领料信息列表
     */
    @ApiOperation(value = "查询领料信息列表")
    @PreAuthorize("@ss.hasPermi('mes:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(PickInfo pickInfo) {
        startPage();
        List<PickInfo> list = pickInfoService.selectPickInfoList(pickInfo);
        return getDataTable(list);
    }

    /**
     * 导出领料信息列表
     */
    @ApiOperation(value = "导出领料信息列表")
    @PreAuthorize("@ss.hasPermi('mes:info:export')")
    @Log(title = "领料信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PickInfo pickInfo) {
        List<PickInfo> list = pickInfoService.selectPickInfoList(pickInfo);
        ExcelUtil<PickInfo> util = new ExcelUtil<PickInfo>(PickInfo.class);
        util.exportExcel(response, list, "领料信息数据");
    }

    /**
     * 获取领料信息详细信息
     */
    @ApiOperation(value = "获取领料信息详细信息")
    @PreAuthorize("@ss.hasPermi('mes:info:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(pickInfoService.selectPickInfoById(id));
    }

    /**
     * 新增领料信息
     */
    @ApiOperation(value = "新增领料信息")
    @PreAuthorize("@ss.hasPermi('mes:info:add')")
    @Log(title = "领料信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PickInfo pickInfo) {
        return toAjax(pickInfoService.insertPickInfo(pickInfo));
    }

    /**
     * 修改领料信息
     */
    @ApiOperation(value = "修改领料信息")
    @PreAuthorize("@ss.hasPermi('mes:info:edit')")
    @Log(title = "领料信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PickInfo pickInfo) {
        return toAjax(pickInfoService.updatePickInfo(pickInfo));
    }

    /**
     * 删除领料信息
     */
    @ApiOperation(value = "删除领料信息")
    @PreAuthorize("@ss.hasPermi('mes:info:remove')")
    @Log(title = "领料信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(pickInfoService.deletePickInfoByIds(ids));
    }

    //********************

    /**
     * 查 - 领料信息分页
     * @param pickInfo
     * @return
     */
    @GetMapping("/pickInfoList")
    public TableDataInfo pickInfoList(PickInfo pickInfo){
        startPage();
        List<PickInfo> list = pickInfoService.pickInfoList(pickInfo);
        return getDataTable(list);
    }

    /**
     * 查 - 领料出库详情
     * @param id 领料id
     * @return
     */
    @GetMapping("/getDetails")
    public AjaxResult getDetails(@RequestParam Long id){
        return pickInfoService.getDetails(id);
    }

    /**
     * 原料出库
     * @param id 领料id
     * @return
     */
    @PostMapping("/outBound")
    public AjaxResult outBound(@RequestParam Long id){
        return pickInfoService.outBound(id);
    }

    /**
     * 删 - 领料出库
     * @param id 领料id
     * @return
     */
    @DeleteMapping("/deletePicks")
    public AjaxResult deletePicks(@RequestParam Long id){
        return pickInfoService.deletePicks(id);
    }


    /**
     * 派遣小车
     * @return
     */
    @PostMapping("/dispatchAvg")
    public AjaxResult dispatchAvg(@RequestParam Long id){
        return pickInfoService.returnToDock1(id);
    }
}
